home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8733 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: more problems with qsort
  5. Date: Wed, 06 Mar 96 01:04:28 GMT
  6. Organization: none
  7. Message-ID: <826074268snz@genesis.demon.co.uk>
  8. References: <177399702S86.JW1675A@american.edu> <4h0j9e$ng5@clarknet.clark.net> <4h8bud$1vd@castle.nando.net> <825783387snz@genesis.demon.co.uk> <4hd2dd$82q@castle.nando.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4hd2dd$82q@castle.nando.net>
  15.            actuary@nando.net "Bill McCarthy" writes:
  16.  
  17. >In <825783387snz@genesis.demon.co.uk>, Lawrence Kirby
  18. > <fred@genesis.demon.co.uk> writes:
  19. >>In article <4h8bud$1vd@castle.nando.net>
  20. >>           actuary@nando.net "Bill McCarthy" writes:
  21. >>
  22. >>>Didn't you mean to type "sizeof( char * )" which, IMHO, could be
  23. >>>better expressed as "sizeof array[0]" ?  Also, there's no need to
  24. >>>further complicate the call of qsort with the cast on compare if
  25. >>>you define compare() as:
  26. >>
  27. >>The code as written requires a diagnostic from the compiler (if stdlib.h
  28. >>is included) because the comparison function type takes const void * arguments
  29. >>and  int (*)(void *, void *)  is incompatible with
  30. >>int (*)(const void *, const void *).
  31. >>
  32. >>Even if the cast is fixed the code results in undefined behaviour since
  33. >>an int (char **, char **) function can't be legally called as an
  34. >>int (const void *, const void *) function which is how qsort() will call it.
  35. >
  36. >OK Lawrence, but you are replying to me.  I made two points:
  37. >
  38. >  (1)  the "sizeof(char **)" should be replaced with "sizeof(char *)"
  39. >  (2)  the cast in front of compare can be eliminated by rewriting compare
  40. >
  41. >Which point did you disagree with?
  42.  
  43. Neither, however it is possible to read "there's no need" as implying that
  44. there's no harm either.  I was just trying to make it clear that it was just
  45. plain wrong (and potentially harmful).
  46.  
  47. -- 
  48. -----------------------------------------
  49. Lawrence Kirby | fred@genesis.demon.co.uk
  50. Wilts, England | 70734.126@compuserve.com
  51. -----------------------------------------
  52.